<?php	

require_once("config_inc.php");

require_once("core/user_api.php");
require_once("core/share_api.php");
require_once("core/gui_api.php");

session_start();

if(!is_active_user_session()) 
{
	header("Location: " . SERVER_URL . "login"); 
 	exit();
}


if(isset($_POST["share_image_project"]))
{
	

	$share_api = new share_api($db);	
	$project_id = $share_api->create_image_project($_POST["project_name"], $_POST["project_desc"], $_SESSION["user_id"], $_FILES["project_file"], $_POST["project_category"]);
	
	$db->close();
	
	header("Location: " . SERVER_URL . "project/" . $project_id); 
 	exit();
}

if(isset($_POST["share_video_project"]))
{
	$db = new database();
	$db->connect();
	
	$share_api = new share_api($db);
	$project_id = $share_api->create_video_project($_POST["project_name"], $_POST["project_desc"], $_SESSION["user_id"], $_POST["project_link"], $_POST["project_category"]);
	
	$db->close();
	
	header("Location: " . SERVER_URL . "project/" . $project_id); 
 	exit();
}

$db = new database();
$db->connect();

$share_api = new share_api($db);
$gui_api = new gui_api($db);

function inset_category_list($share_api, $type)
{
	if($result = $share_api->get_category_list())
	{
		while($row = $result->fetch_assoc())
		{
			?>
            <input type="radio" name="project_category" value="<?=$row["CAT_ID"]?>" id="<?=$type . "_" . $row["CAT_ID"]?>" />
            <label for="<?=$type . "_" . $row["CAT_ID"]?>" class="radio-label"><?=$row["CAT_NAME"]?></label>
			<?php
		}

		$result->free();
	}
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<?php require_once("meta_inc.php"); ?>
<script type="text/javascript" src="<?=SERVER_URL?>js/jquery.validate.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {	

	$("#tabs-box a").click(function(e) {	
		e.preventDefault();		
		$($(this).attr("href")).show().siblings().hide();
		$(this).parent().addClass("active").siblings().removeClass("active");		
    });
	
	$("#form_panel_image").validate({
		rules: {
			project_name : "required",			
			project_file : {required:true},
			project_category : "required"
		},
		errorPlacement: function(error, element) { error.appendTo( element.parent("td").next("td") ); }
	});
	
	$("#form_panel_video").validate({
		rules: {
			project_name : "required",			
			project_link : {required: true, url: true}
		},
		errorPlacement: function(error, element) { error.appendTo( element.parent("td").next("td") ); }
	});
	
	$("#form_panel_text").validate({
		rules: {
			project_name : "required"
		},
		errorPlacement: function(error, element) { error.appendTo( element.parent("td").next("td") ); }
	});
	
	
});
</script>
</head>
<body>

<?php require_once("topbar_inc.php"); ?> 

<div class="wrapper" style="margin-top:80px">
	
    <div class="left-column-right">
    	<div class="small-white-page input-form">
			<div class="sub-gray-title">recommended</div>
			<?=$gui_api->insert_feed_list(FEED_TYPE_RECOMENDED, 3);?>
			<div class="sub-gray-title">subscriptions</div>
			<?=$gui_api->insert_feed_list(FEED_TYPE_SUBSCRIPTION, 3);?>
		</div>
    </div>
        
    <div class="right-column-right">
    	<div class="input-form big-white-page">
        
        	<h1>create your project</h1>
            
			<ul class="nav nav-tabs" id="tabs-box">
				<li class="active"><a href="#image-panel">image</a></li>
				<li><a href="#video-panel">video</a></li>
				<li><a href="#text-panel">text</a></li>
			</ul>
			
			<div class="tab-content">
				<div class="tab-pane active" id="image-panel">
				
				<form action="<?=SERVER_URL?>share" method="post" enctype="multipart/form-data" id="form_panel_image">
                <table cellpadding="5" cellspacing="5">
                <tr>
                    <td align="right"><span class="info-text">project name</span></td>
                    <td><input type="text" placeholder="project name" name="project_name" /></td>
					<td></td>
                </tr>  
                <tr>
                    <td align="right"><span class="info-text">category</span></td>
                    <td><?=inset_category_list($share_api, "pimage"); ?></td>
					<td></td>
                </tr>          
                <tr>
                    <td align="right"><span class="info-text">image</span></td>
                    <td><input type="file" name="project_file" /><br /><a href="#" class="small-link ">add more image</a></td>
					<td></td>
                </tr>				
                <tr>
                    <td valign="top" align="right"><span class="info-text">project description</span></td>
                    <td colspan="2"><textarea placeholder="description" rows="6" name="project_desc" style="width:550px"></textarea></td>					
                </tr>
                <tr>
                    <td />
                    <td><input type="submit" value="share project" name="share_image_project" /></td>
                </tr>
                </table>
                </form>
				
				</div>
				
				
				<div class="tab-pane" id="video-panel">
				
				<form action="<?=SERVER_URL?>share" method="post" id="form_panel_video">
                <table cellpadding="5" cellspacing="5">
                <tr>
                    <td align="right"><span class="info-text">project name</span></td>
                    <td><input type="text" name="project_name" placeholder="project name" /></td>
					<td></td>
                </tr>
                <tr>
                    <td align="right"><span class="info-text">category</span></td>
                    <td><?=inset_category_list($share_api, "pvideo"); ?></td>
                </tr>            
                <tr>
                    <td align="right"><span class="info-text">video url</span></td>
                    <td><input type="url" placeholder="http://" name="project_link" /></td>
					<td></td>
                </tr>
                <tr>
                    <td valign="top" align="right"><span class="info-text">project description</span></td>
                    <td colspan="2"><textarea placeholder="description" rows="6" name="project_desc" style="width:550px"></textarea></td>
                </tr>
                <tr>
                    <td />
                    <td><input type="submit" value="share project" name="share_video_project" /></td>
                </tr>
                </table>
                </form>
				
				
				</div>
				
				
				<div class="tab-pane" id="text-panel">
				
				<form action="<?=SERVER_URL?>share" method="post" id="form_panel_text">
                <table cellpadding="5" cellspacing="5">
                <tr>
                    <td align="right"><span class="info-text">project name</span></td>
                    <td><input type="text" name="project_name" placeholder="project name" /></td>
					<td></td>
                </tr>   
                <tr>
                    <td align="right"><span class="info-text">category</span></td>
                    <td><?=inset_category_list($share_api, "ptext"); ?></td>
                </tr>
                <tr>
                    <td colspan="2"><div class="sub-title">projekty</div></td>
                </tr>
                <tr>
                    <td valign="top" align="right"><span class="info-text">text</span></td>
                    <td colspan="2"><textarea name="project_text" style="width:550px" rows="8"></textarea></td>
                </tr>
                <tr>
                    <td valign="top" align="right"><span class="info-text">project description</span></td>
                    <td colspan="2"><textarea placeholder="description" rows="6" name="project_desc" style="width:550px"></textarea></td>
                </tr>  
                <tr>
                    <td />
                    <td><input type="submit" value="share project" name="share_video_project" /></td>
                </tr>     
                </table>
           	 	</form>
				
				</div>
				
			</div>
                   
              		                            
        </div>
    </div>

    <div class="clear"></div>
       
</div>    

<?php require_once("bottombar_inc.php"); ?>	

</body>
</html>
<?php $db->close(); ?>